package dealer;

import java.util.ArrayList;
import java.util.Random;

class GoodRow {
	String GoodName;
	String CityName;
	int Quantity;
	int Price;
	
	public GoodRow(String Good, String City, int initPrice, int initQuantity){
		this.GoodName = Good;
		this.CityName = City;
		this.Price = initPrice;
		this.Quantity = initQuantity;
	}
}
	

public class GoodGrid {
  
  private ArrayList<GoodRow> DataGrid; 
  
  public GoodGrid(){
	  DataGrid = new ArrayList<GoodRow>();
	  PopulateData();
  }


  private void PopulateData(){
		

	  
	for (int g=0; g < GoodList.Goods.length; g++){
	  for (int c=0; c < CityList.Cities.length; c++){
		  Random RndGen = new Random(CityList.CityRandomSeed[c]);
		  
		  DataGrid.add(new GoodRow(
				  				GoodList.Goods[g], 
				  				CityList.Cities[c], 
				  				(int) (GoodList.Prices[g]*CityList.PriceMods[c]*RndGen.nextGaussian()), 
				  				10
				  			)
		  );
	  }
    }
  }
  
  void ShowCity(String city){
	  for (int i=0; i < DataGrid.size(); i++){
		  if (DataGrid.get(i).CityName.equals(city)){
			  System.out.println(DataGrid.get(i).GoodName+";"+DataGrid.get(i).Quantity+";"+DataGrid.get(i).Price);
		  }
	  }
  }
  
  
  ArrayList<GoodRow> getCity(String city){
	  ArrayList<GoodRow> CityGrid = new ArrayList<GoodRow>();
	  
	  for (int i=0; i < DataGrid.size(); i++){
		  if (DataGrid.get(i).CityName.equals(city)){
			  CityGrid.add(DataGrid.get(i));
		  }
	  
	  
		  
	  }
	  
	  return CityGrid;
  }
  

  //tieto for-cykly treba prepisat na while, aby sa neprehladaval cely grid, ale len pokial treba
  public int getUnitPrice(String cityName, String goodName){

	  int retval=0;
	  for (int i=0; i < DataGrid.size(); i++){
		  if (DataGrid.get(i).CityName.equals(cityName) && DataGrid.get(i).GoodName.equals(goodName)){
			  retval = DataGrid.get(i).Price;
		  }
	  }
	  
	  return retval;
  }
  
  public void removeGood(String cityName, String goodName, int amount){
	  for (int i=0; i < DataGrid.size(); i++){
		  if (DataGrid.get(i).CityName.equals(cityName) && DataGrid.get(i).GoodName.equals(goodName)){
			  DataGrid.get(i).Quantity -= amount;
		  }
	  }
  }


public static void runEndOfDay() {
	// TODO Auto-generated method stub
	
}
  
  
  
}